package hu.mapro.jam.commons;

import java.io.BufferedReader;
import java.io.File;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.text.MessageFormat;
import java.util.Scanner;

import org.junit.Test;

abstract public class Problem {

	protected String letter;
	protected boolean practice;
	
	public Problem(String letter) {
		this(letter, false);
	}

	public Problem(String letter, boolean practice) {
		super();
		this.letter = letter;
		this.practice = practice;
	}

	@Test
	public void sample() throws Exception {
		solve("sample");
	}
	
	@Test
	public void small() throws Exception {
		solve("small");
	}
	
	@Test
	public void large() throws Exception {
		solve("large");
	}
	
	private String postfix() {
		return practice ? "-practice" : "";
	}
	
	void solve(String fileName) throws Exception {
		String resourceName = MessageFormat.format(
				"/{0}-{1}{2}.{3}", 
				letter,
				fileName,
				postfix(),
				"in"
		);
		
		InputStream is = Problem.class.getResourceAsStream(
				resourceName
		);
		
		if (is==null) {
			String message = "Could not find resource: " + resourceName;
			System.out.println(message);
			throw new RuntimeException(message);
		}

		Scanner in = new Scanner(is);
		
		int T = in.nextInt();

		PrintWriter out = new PrintWriter(new File(
				MessageFormat.format(
						"target/{0}-{1}{2}.{3}", 
						letter,
						fileName,
						postfix(),
						"out"
						)
				)
		);
		
		for (int t = 1 ; t <= T ; t++) {
			System.out.println("Solving: " + t);
			
			String result = solve(in);

			out.println(MessageFormat.format("Case #{0}: {1}", Integer.toString(t), result));
		}
		
		out.close();
	}

	protected abstract String solve(Scanner in);
	

}
